<template>
  <div class="count">
    <h2>当前求和为：{{ countStore.sum }}</h2>
    <select v-model.number="n">
      <!-- 收集的值类型为数字 -->
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="add">加</button>
    <button @click="minus">减</button>
  </div>
</template>

<script setup lang="ts" name="Count">
import { ref } from "vue";

// 1.引入useCountStore这个
import { useCountStore } from "@/store/count";
// 2.调用useXxxxxStore得到对应的store
const countStore = useCountStore(); // 返回一个用reactive创建的响应式对象
// 3.获取state中的数据方法一(常用)
console.log(countStore.sum); 
 // 获取state中的数据方法二
console.log(countStore.$state.sum);

// 数据
let n = ref(1); // 用户选择的数据(响应式)

function add() {}
function minus() {}
</script>

<style scoped>
.count {
  background-color: skyblue;
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 0 10px;
}
select,
button {
  margin: 0 5px;
  height: 25px;
}
</style>
